import threading
import time
from threading import Thread, Lock

tickets = 100

def task(num):
    global tickets
    mutex.acquire()#上鎖，线程安全
    time.sleep(0.1)
    tickets -= num
    print(f'剩余票数 {tickets} , thread name {threading.current_thread().name}')
    mutex.release()

if __name__ == '__main__':
    mutex = Lock()
    t_list = []

    count = 0
    while(count < 10):
        count += 1
        for i in range(10):
            t = Thread(target=task, args=(1,))
            t_list.append(t)
            t.start()

